﻿using AutoMapper;
using B.R.RabbitRoot.Domain.animal_husbandry;
using B.R.RabbitRoot.ErrorCode;
using B.R.RabbitRoot.Infrastructure.Interface;
using B.R.RabbitRoot.Write.API.Applications.Commands.HealthCareCommands;
using MediatR;

namespace B.R.RabbitRoot.Write.API.Applications.Commandhandlers.HealthCareCommandHandler
{
    /// <summary>
    /// 保健信息命令添加处理
    /// </summary>
    public class HealthCareCreamCommandHandler : IRequestHandler<HealthCareCreamCommand, APIResult<int>>
    {
        private readonly IBaserepository<HealthCareInfo> _HealthCareInfo;
        private readonly IMapper _mapper;

        public HealthCareCreamCommandHandler(IBaserepository<HealthCareInfo> healthCareInfo, IMapper mapper)
        {
            _HealthCareInfo = healthCareInfo;
            _mapper = mapper;
        }

        public async Task<APIResult<int>> Handle(HealthCareCreamCommand request, CancellationToken cancellationToken)
        {
           APIResult<int> result=new APIResult<int>();
           var list=_mapper.Map<HealthCareInfo>(request);
           var entity=await _HealthCareInfo.AddAsync(list);
            return await Task.FromResult(result.Success(entity)); 
        }
    }
}
